let arr = [1, 2, 3, 4, 5, 6];

// let a = arr[0], b = arr[1], c = arr[2];

// 解构赋值
// let [a, b, c] = arr; // 一一对应
let [a, b, ...c] = arr; // c是一个数组

console.log(a, b, c);


let obj = {
    name: "zhangsan",
    age: 18,
    gender: '男'
};

// let name = obj.name;
// let age = obj['age'];
// let gender = obj.gender;

// 对象解构， 变量名要和对象的属性名一致。如果想要改变变量名，可以使用别名 字段名:变量名
// let { gender, age, name: n } = obj;
// console.log(n, age, gender);

let { age } = obj;

console.log(age);

// let random = Math.random;
let { random, abs } = Math;
let { log, error, info } = console;

let hello = "a";

let obj2 = {
    hello: "hello world",
    // fn() {
    //     console.log(this.hello);
    // }
    fn: function () {
        console.log(this.hello);
    }
};

// 改变 hello 变量的值为 obj2.hello
// hello = obj2.hello;
// let { hello:h } = obj2; hello = h;
// ({ hello } = obj2);

let { name = 'lisi' } = obj2;

log(name);

log(obj2);






